local players = {};

Route:game("GETALLPLAYERNAME",function(player,bytes)
    player.user.playersinfo = player.user.playersinfo or NetServer:createSyncValue(player,"players","");
    local str = "";
    for i = 1,#players do
        str = str .. players[i].name .. " " .. players[i].index .. " "
    end
    player.user.playersinfo.value = str;
end);

Route:game("SYNCINFO",function(player,bytes)
    local syncValue = NetServer:createSyncValue(player,"info","");
    player.user["SyncInformation"] = Timer:schedule(function()
        syncValue.value = player.velocity.x * player.velocity.x + player.velocity.y * player.velocity.y;
    end,0,4);
end);
Route:game("UNSYNCINFO",function(player,bytes)
    if player.user["SyncInformation"] ~= nil then
        player.user["SyncInformation"]:cancel();
        player.user["SyncInformation"] = nil;
    end
end);

if Game then
    Event:addEventListener(Event.OnPlayerConnect,function(self,player)
        players[#players+1] = player;
    end);

    Event:addEventListener(Event.OnPlayerDisconnect,function(self,player)
        for i = 1,#players do
            if players[i] == player then
                table.remove(players,i);
                break;
            end
        end
    end);
end


if UI then
    local syncValue = NULL;
    local item = Item("显示玩家信息");
    item.call = function(item)
        if syncValue == NULL then
            syncValue = NetClient:createSyncValue("players",function(self)
                item.children = {};
                item:addItem(Item(self.value,function() return true end));
                MainMenu.cursor = item;
                MainMenu:repaint();
            end);
        end

        NetClient:request(Request(Route.Game.GETALLPLAYERNAME),function(bytes)
            print(syncValue.value)
        end);
    end;
    MainMenu.root:addItem(item,1);
end